package com.wish.controller;


import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.wish.dto.ContractDto;
import com.wish.entity.TCfContract;
import com.wish.service.ITCfContractService;
import com.wish.vo.ResultEntity;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author 五组
 * @since 2021-03-29
 */
@RestController
@RequestMapping("/wish.fangyuan/t-cf-contract")
public class TCfContractController {
    @Resource
    private ITCfContractService ITCfContractService;

    @RequestMapping("selects")
    public ResultEntity selects(ContractDto contractDto){
        PageHelper.startPage(contractDto.getPageNum(),contractDto.getPageSize());
        QueryWrapper<TCfContract> wrapper = new QueryWrapper<>();
        if(contractDto.getTenantName()!=null){
            wrapper.like("tenant_name",contractDto.getTenantName());
        }
        if(contractDto.getTenantPhone()!=null){
            wrapper.like("tenant_phone",contractDto.getTenantPhone());
        }
        if(contractDto.getSignType()!=null){
            wrapper.like("sign_type",contractDto.getSignType());
        }
        if(contractDto.getPremiseName()!=null){
            wrapper.like("premise_name",contractDto.getPremiseName());
        }
        if(contractDto.getStartDate()!=null){
            wrapper.eq("start_date",contractDto.getStartDate());
        }
        if(contractDto.getCfContractNo()!=null){
            wrapper.like("cf_contract_no",contractDto.getCfContractNo());
        }
        if(contractDto.getT1()!=null){
            wrapper.gt("input_date",contractDto.getT1());
        }
        if(contractDto.getT2()!=null){
            wrapper.lt("input_date",contractDto.getT2());
        }
        List<TCfContract> list = ITCfContractService.list(wrapper);
        PageInfo<TCfContract> info = new PageInfo<>(list);
        return ResultEntity.ok("200","查询成功",info);
    }

}
